package com.guoxin.designpattern.chapter4.thread;

import com.guoxin.designpattern.chapter4.thread.LifeCycleListener;

/**
 * @author guoxin
 * @date 2019/9/3
 */
public abstract class ObserverRunnable implements Runnable {

    protected final LifeCycleListener listener;

    protected ObserverRunnable(final LifeCycleListener listener) {
        this.listener = listener;
    }

    protected void notifyChange(final RunnableEvent event){
        listener.onEvent(event);
    }

    public enum RunningState{
        RUNNING,ERROR,DONE
    }
    public static class RunnableEvent{
        private final RunningState state;
        private final Thread thread;
        private final Throwable throwable;

        public RunnableEvent(RunningState state, Thread thread, Throwable throwable) {
            this.state = state;
            this.thread = thread;
            this.throwable = throwable;
        }

        public RunningState getState() {
            return state;
        }

        public Thread getThread() {
            return thread;
        }

        public Throwable getThrowable() {
            return throwable;
        }
    }

}
